﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data.Linq;
using System.Data.Linq.Mapping;
using UCenter.Core.Model;

namespace UCenter.Models
{
    [Table(Name = "dbo.Module")]
    public class Module : EntityBase
    {
        #region Private Fields

        private int _Id;

        private string _name;

        private string _entryPoint;

        private string _displayName;

        private string _description;

        private bool _suppressible;

        private EntitySet<History> _histories;

        private EntitySet<UserModuleMap> _userModuleMaps;

        #endregion

        #region Constructor

        public Module()
        {
            this._histories = new EntitySet<History>(new Action<History>(this.AttachHistories), new Action<History>(this.DetachHistories));
            this._userModuleMaps = new EntitySet<UserModuleMap>(new Action<UserModuleMap>(this.AttachUserModuleMaps), new Action<UserModuleMap>(this.DetachUserModuleMaps));
        }

        #endregion

        #region Public Properties

        [Column(Name = "ID", Storage = "_Id", AutoSync = AutoSync.OnInsert, DbType = "Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
        public int ID
        {
            get
            {
                return this._Id;
            }
            set
            {
                if (this._Id != value)
                {
                    this.SendPropertyChanging("ID");
                    this._Id = value;
                    this.SendPropertyChanged("ID", value);
                }
            }
        }

        [Column(Name = "ModuleName", Storage = "_name", DbType = "VarChar(64) NOT NULL", CanBeNull = false)]
        public string Name
        {
            get
            {
                return this._name;
            }
            set
            {
                if (this._name != value)
                {
                    this.SendPropertyChanging("Name");
                    this._name = value;
                    this.SendPropertyChanged("Name", value);
                }
            }
        }

        [Column(Name = "EntryPoint", Storage = "_entryPoint", DbType = "VarChar(64) NOT NULL", CanBeNull = false)]
        public string EntryPoint
        {
            get
            {
                return this._entryPoint;
            }
            set
            {
                if (this._entryPoint != value)
                {
                    this.SendPropertyChanging("EntryPoint");
                    this._entryPoint = value;
                    this.SendPropertyChanged("EntryPoint", value);
                }
            }
        }

        [Column(Name = "DisplayName", Storage = "_displayName", DbType = "VarChar(64)", CanBeNull = true)]
        public string DisplayName
        {
            get
            {
                return this._displayName;
            }
            set
            {
                if (this._displayName != value)
                {
                    this.SendPropertyChanging("DisplayName");
                    this._displayName = value;
                    this.SendPropertyChanged("DisplayName", value);
                }
            }
        }

        [Column(Name = "Description", Storage = "_description", DbType = "VarChar(4000) NOT NULL", CanBeNull = false)]
        public string Description
        {
            get
            {
                return this._description;
            }
            set
            {
                if (this._description != value)
                {
                    this.SendPropertyChanging("Description");
                    this._description = value;
                    this.SendPropertyChanged("Description", value);
                }
            }
        }

        [Column(Name = "Suppressible", Storage = "_suppressible", DbType = "Bit NOT NULL")]
        public bool Suppressible
        {
            get
            {
                return this._suppressible;
            }
            set
            {
                if (this._suppressible != value)
                {
                    this.SendPropertyChanging("Suppressible");
                    this._suppressible = value;
                    this.SendPropertyChanged("Suppressible", value);
                }
            }
        }

        [Association(Name = "Module_History", Storage = "_histories", OtherKey = "ModuleId")]
        public EntitySet<History> Histories
        {
            get
            {
                return this._histories;
            }
            set
            {
                this._histories.Assign(value);
            }
        }

        [Association(Name = "Module_UserModuleMap", Storage = "_userModuleMaps", OtherKey = "ModuleId")]
        public EntitySet<UserModuleMap> UserModuleMaps
        {
            get
            {
                return this._userModuleMaps;
            }
            set
            {
                this._userModuleMaps.Assign(value);
            }
        }

        #endregion

        #region Attach and Detach Methods

        private void AttachHistories(History entity)
        {
            entity.Module = this;
        }

        private void DetachHistories(History entity)
        {
            entity.Module = null;
        }

        private void AttachUserModuleMaps(UserModuleMap entity)
        {
            entity.Module = this;
        }

        private void DetachUserModuleMaps(UserModuleMap entity)
        {
            entity.Module = null;
        }

        #endregion
    }
}
